var specialConsole = (function(){
    var consoleLineForCloning = document.createElement('span');
    var console;

    function createConsole(){
        var container = document.getElementById('console-container');
        console = document.createElement('div');

        console.style.width = '800px';
        console.style.height = '600px';
        console.style.fontFamily = 'Arial';
        console.style.fontSize = '12px';
        console.style.color = 'white';
        console.style.backgroundColor = '#442F1C';

        container.appendChild(console);
    }

    function getPlaceholders(args){
        var placeholders = [];

        for (var i = 1; i < args.length; i++) {
            placeholders.push(args[i]);
        }

        return placeholders;
    }

    function formatString(str, args){
        for (var i = 0, placeholder = 0; i < args.length; i++, placeholder++) {
            var current = '\{' + placeholder + '\}';

            str = str.replace(current, args[i].toString(), 'g');
        }

        return str;
    }

    function writeLine(str) {
        var consoleLine = consoleLineForCloning.cloneNode(true);

        if (arguments.length > 1){
            var argsArray = getPlaceholders(arguments);
            str = formatString(str, argsArray);
        }

        consoleLine.textContent = str.toString();
        console.appendChild(consoleLine);
        console.appendChild(document.createElement('br'));
    }

    return {
        createConsoleIn : createConsole,
        writeLine : writeLine,
        writeError: writeLine,
        writeWarning : writeLine
    }
})();

specialConsole.createConsoleIn('#console-holder');
specialConsole.writeLine('Message: hello');
specialConsole.writeLine('Message: {0}, {1}', 'hello', 'Ivan');